import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// ignore: must_be_immutable
class SliverPage extends StatefulWidget {
  SliverPage({Key key, this.title, this.list}) : super(key: key);
  String title;
  List list;
  @override
  _SliverPageState createState() => _SliverPageState();
}

class _SliverPageState extends State<SliverPage> {
  List slivergrid = [
    {"name": "我的预约", "code": "id1"},
    {"name": "看房报告", "code": "id2"},
    {"name": "我的卡片", "code": "id3"},
    {"name": "我的收藏", "code": "id4"},
  ];
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(10.0),
      child: Container(
        padding: EdgeInsets.all(8.0),
        decoration: BoxDecoration(
          border: Border.all(width: 1.0, color: Colors.grey[300]),
          borderRadius: BorderRadius.all(
            Radius.circular(10.0),
          ),
        ),
        child: sliver(),
      ),
    );
  }

  Widget sliver() {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: EdgeInsets.only(left: ScreenUtil().setWidth(16)),
            child: Text(
              widget.title,
              style: TextStyle(fontSize: ScreenUtil().setSp(38)),
            ),
          ),
          SizedBox(
            height: ScreenUtil().setHeight(16),
          ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: _listView(),
          ),
        ],
      ),
    );
  }

  List<Widget> _listView() {
    return widget.list
        .map(
          (f) => Container(
            child: InkWell(
              onTap: () => print(f),
              child: Column(
                children: <Widget>[
                  ClipOval(
                    child: Image.network(
                        'https://wx2.sinaimg.cn/mw690/66fa6be4gy1fzd1sif9tuj218g0p143d.jpg',
                        width: 60.0,
                        height: 60.0,
                        fit: BoxFit.cover),
                  ),
                  SizedBox(height: 5),
                  Text(
                    f['name'],
                  )
                ],
              ),
            ),
          ),
        )
        .toList();
  }
}
